﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace lcs.Web.Outstorage
{
    public partial class ListSHZ : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Session["login"] != null)
                {
                    DataSet ds = Session["login"] as DataSet;

                    int roles_id = Convert.ToInt32(ds.Tables[0].Rows[0]["roles_id"].ToString());
                    int user_id = Convert.ToInt32(ds.Tables[0].Rows[0]["user_id"].ToString());

                    if (roles_id == 3)//材料员
                    { 
                        Bind(user_id);
                    }
                    else
                    {
                        ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('您不是材料员！');</script>");
                    }
                }
                else
                {
                    Maticsoft.Common.MessageBox.Show(this, "由于长时间未操作，登录信息已过期，请重新登陆!");
                }


            }
        }

        protected void btn_selectProject_Click(object sender, EventArgs e)
        {
            if (Session["login"] != null)
            {
                DataSet ds = Session["login"] as DataSet;

                int roles_id = Convert.ToInt32(ds.Tables[0].Rows[0]["roles_id"].ToString());
                int user_id = Convert.ToInt32(ds.Tables[0].Rows[0]["user_id"].ToString());

                if (roles_id == 3)//材料员
                {
                    Bind(user_id);
                }
                else
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('您不是材料员！');</script>");
                }
            }
            else
            {
                Maticsoft.Common.MessageBox.Show(this, "由于长时间未操作，登录信息已过期，请重新登陆!");
            }
        }


        private void Bind(int user_id)
        {
            if (string.IsNullOrEmpty(this.txt_projectName.Text))
            {
                ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('请选择出库项目！');</script>");
                return;
            }

            string where = " material_user_id=" + user_id + " and isDone='False' ";
            if (!string.IsNullOrEmpty(this.txt_material.Text))
            {
                where += " and material like '%" + this.txt_material.Text + "%' ";

            }
            string proid = this.txt_projectName.Text.Split('|')[1];

            where += " and proid='" + proid + "' ";

            DataSet ds = new lcs.BLL.user_project().GetSHZOutList(where);

            this.GridView1.DataSource = ds;
            this.GridView1.DataBind();
        }


        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)//判定当前的行是否属于datarow类型的行
            {
                //当鼠标放上去的时候 先保存当前行的背景颜色 并设置新的背景色
                e.Row.Attributes.Add("onmouseover", "onmouseroverop(this)");
                //当鼠标离开的时候 将背景颜色恢复成之前的颜色
                e.Row.Attributes.Add("onmouseout", "onmouseroutop(this)");
                //单击行改变行背景颜色
                e.Row.Attributes.Add("onclick", "ItemOver(this)");
            }
        }

        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName=="lbn_see")
            {
                string obid = e.CommandArgument.ToString();

                ClientScript.RegisterStartupScript(this.GetType(), "", "<script>OpenPopWin('ListSHJD.aspx?obid="+ obid + "', '500px', '300px')</script>");
            }
        }
    }
}